<?php

namespace Lib;

class Uc {

	public function __construct() {
		global $o;
		try {
			$sPath = $o->Config->get ( '3thlib.path' );
			if ($sPath == null) {
				throw new ExceptionExt ( '第三方类库目录不存在' );
			}
			if (is_file ( $sPath . '/uc_client/client.php' )) {
				if (! defined ( 'UC_API' )) {
					define ( 'UC_API', true );
					define ( 'UC_CONNECT', $o->Config->get ( 'uc.connect' ) );
					define ( 'UC_DBHOST', $o->Config->get ( 'uc.dbhost' ) );
					define ( 'UC_DBUSER', $o->Config->get ( 'uc.dbuser' ) );
					define ( 'UC_DBPW', $o->Config->get ( 'uc.dbpw' ) );
					define ( 'UC_DBNAME', $o->Config->get ( 'uc.dbname' ) );
					define ( 'UC_DBCHARSET', $o->Config->get ( 'uc.dbcharset' ) );
					define ( 'UC_DBTABLEPRE', $o->Config->get ( 'uc.dbtablepre' ) );
					define ( 'UC_DBCONNECT', $o->Config->get ( 'uc.dbconnect' ) );
					define ( 'UC_KEY', $o->Config->get ( 'uc.key' ) );
					define ( 'UC_API', $o->Config->get ( 'uc.api' ) );
					define ( 'UC_CHARSET', $o->Config->get ( 'uc.charset' ) );
					define ( 'UC_IP', $o->Config->get ( 'uc.ip' ) );
					define ( 'UC_APPID', $o->Config->get ( 'uc.appid' ) );
					define ( 'UC_PPP', $o->Config->get ( 'uc.ppp' ) );
				}
				require_once $sPath . '/uc_client/client.php';
			} else {
				throw new ExceptionExt ( '请先安装UC_CLIENT' );
			}
		} catch ( ExceptionExt $e ) {
			$e->showError ();
		}
	}

	public function __call($sName, $aParam) {
		if (function_exists ( $sName )) {
			return call_user_func_array ( $sName, $aParam );
		} elseif (function_exists ( 'uc_' . $sName )) {
			return call_user_func_array ( 'uc_' . $sName, $aParam );
		} else {
			return false;
		}
	}
}

?>